<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

// Code here is run before ALL controllers
class MY_Controller extends Controller
{
	var $module;
	var $controller;
	var $method;

	function MY_Controller()
	{

		parent::Controller();
        // Make sure we have the user module
      	if( ! is_module('users') )
        {
        	show_error('The user module is missing.');
        }

        else
        {
	        // Load the user model and get user data
	        $this->load->module_model('users', 'users_m');
	        $this->load->module_library('users', 'user_lib');

	        $this->data->user =& $this->user_lib->user_data;
        }
        // Work out module, controller and method and make them accessable throught the CI instance
        $this->module 				= str_replace(array('modules/', '/'), '', $this->matchbox->fetch_module());
        $this->controller			= strtolower(get_class($this));
        $s 							= $this->uri->rsegment_array();
        $n 							= array_search($this->controller, $s);
        $this->method 				= $this->uri->rsegment($n+1);
		// Get meta data for the module
        $this->module_data 			= $this->cache->model('modules_m', 'getModule', array($this->module), $this->cache->cache_timeout);
	    								//$this->modules_m->getModule($this->module);

        // Make them available to all layout files
        //$this->data->module_data	=& $this->module_data;
        $this->data->module 		=& $this->module;
        $this->data->controller 	=& $this->controller;
        $this->data->method 		=& $this->method;
        $this->layout->set_metadata('canonical', $this->uri->full_url_address(), 'link');
	}

    /**
    * Thực hiện gọi và xử lý nghiệp vụ ở tầng business
    *
    * @param ReflectionMethod $method
    */
    function _processBusiness($businessname,$method,$args=array())
    {
        //Tiến hành gọi sang BusinessController
        require_once dirname(__FILE__)."/Business_Controller.php";
        $bController=new Business_Controller();
        return $bController->_processBusiness($businessname,$method,$args);
    }

	/**
	* ghi log khi gui mail loi
	*
	* @param mixed $error
	*/
	function insert_log($error){
		$this->load->model('insert_log_m');
		$this->insert_log_m->insert(array('log'=>$error));
	}
}

include(APPPATH . 'libraries/Public_Controller'.EXT);
include(APPPATH . 'libraries/Admin_Controller'.EXT);


